<?php
class Debug
{
	const DEBUG = 0;
	const INFO = 1;
	const WARNING = 2;
	const ERROR = 3;
	const FATAL = 9;
	
	private static $currentLevel = 2;
	private static $logFormat = "%timestamp% <%logLevel%>: %message%";
	
	public static function log($aString, $aLevel = 0)
	{
		if ($aLevel >= self::$currentLevel || $aLevel == self::FATAL)
		{
			$message = self::$logFormat;
			$message = str_replace("%timestamp%", date("Y/M/d H:m:s"), $message);
			$message = str_replace("%logLevel%", self::getLogLevel($aLevel), $message);
			$message = str_replace("%message%", $aString, $message);
			Console::write($message);
			
			if ($aLevel == self::FATAL)
				die();
		}
	}
	
	public static function setLogLevel($aLevel)
	{
		self::$currentLevel = $aLevel;
	}
	
	private static function getLogLevel($aLevel)
	{
		switch ($aLevel)
		{
			case self::DEBUG: return "debug";
			case self::INFO: return "info";
			case self::WARNING: return "warning";
			case self::ERROR: return "error";
		}
		
		return "unknown";
	}
}
?>